package com.thl.thl_advertlibrary.permissions;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;

import androidx.core.content.ContextCompat;

import com.bytedance.sdk.openadsdk.TTCustomController;
import com.thl.thl_advertlibrary.config.AppBuildConfig;
import com.thl.thl_advertlibrary.utils.Fhad_DeviceUtil;

public class PermissionController extends TTCustomController {
    private final boolean isAcceptedPrivacy;

    private Context mContext;

    public PermissionController(Context context) {
        this(context, false);
    }

    public PermissionController(Context context, boolean isAcceptedPrivacy) {
        this.mContext = context.getApplicationContext();
        this.isAcceptedPrivacy = isAcceptedPrivacy;
    }

    /**
     * 是否允许SDK主动使用地理位置信息
     *
     * @return true可以获取，false禁止获取。默认为true
     */
    @Override
    public boolean isCanUseLocation() {
        return isAcceptedPrivacy || ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
    }

    /**
     * 是否允许SDK主动使用手机硬件参数，如：imei
     *
     * @return true可以使用，false禁止使用。默认为true
     */
    @Override
    public boolean isCanUsePhoneState() {
        return isAcceptedPrivacy || ContextCompat.checkSelfPermission(mContext, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED;
    }

    /**
     * 是否允许SDK主动使用ACCESS_WIFI_STATE权限
     *
     * @return true可以使用，false禁止使用。默认为true
     */
    @Override
    public boolean isCanUseWifiState() {
        return isAcceptedPrivacy || ContextCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_WIFI_STATE) == PackageManager.PERMISSION_GRANTED;
    }

    /**
     * 是否允许SDK主动使用WRITE_EXTERNAL_STORAGE权限
     *
     * @return true可以使用，false禁止使用。默认为true
     */
    @Override
    public boolean isCanUseWriteExternal() {
        return isAcceptedPrivacy || ContextCompat.checkSelfPermission(mContext, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
    }

    /**
     * 当isCanUsePhoneState=false时，可传入imei信息，穿山甲sdk使用您传入的imei信息
     *
     * @return imei信息
     */
    @Override
    public String getDevImei() {
        return AppBuildConfig.getInstance().getCustomDeviceID(mContext);
    }
}
